using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAttribute : MonoBehaviour
{
    [Range(1,10)]
    [SerializeField] private int playerHealth;
    public Transform playerRespawner;

    public int PlayerHealth => playerHealth;

    public static PlayerAttribute Instance;
    private PlayerArrow playerArrow;
    public PlayerArrow PlayerArrow => playerArrow;
    public bool hasArrow;
    [SerializeField] private ParticleSystem arrowRecycleParticle;
    [SerializeField] private ParticleSystem walkParticle;
    [SerializeField] private ParticleSystem playerHurtParticle;
    public ParticleSystem playerAcquireParticle;

    private void Awake()
    {
        Instance = this;
        hasArrow = true;
        playerArrow = GetComponent<PlayerArrow>();
    }
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void PlayerGetHurt(int damage)
    {
        if (playerHealth - damage < 0)
        {
            PlayerDead();
        }
        else
        {
            playerHealth -= damage;
        }
        playerHurtParticle.Play();
    }

    private void PlayerDead()
    {
        PlayerRespawn(playerRespawner.position);
    }

    private void PlayerRespawn(Vector3 position)
    {
        transform.parent.transform.position = new Vector3(position.x,position.y,0) ;
    }

    public void ShootArrow(Vector2 velocity,Vector3 offSet)
    {
        playerArrow.ShootArrow(velocity,offSet);
        hasArrow = false;
    }

    public void ArrowRecycle()
    {
        playerArrow.RecycleArrow();
        arrowRecycleParticle.Play();
        hasArrow = true;
    }

    public void SetWalkPartivle(bool enabled)
    {
        switch (enabled)
        {
            case true:
                walkParticle.Play();
                break;
            case false:
                walkParticle.Stop();
                break;
        }
    }
    
}
